package com.cai.quartz.listener.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

@Slf4j
public class MyJobListener1 implements JobListener {
    public MyJobListener1() {
        log.info("开启Job监听器：【MyJobListener1】");
    }

    /**
     * 监听器的名称
     */
    @Override
    public String getName() {
        String name=this.getClass().getSimpleName();
        log.info("监听器名称是：{}",name);
        return name;
    }

    /**
     * Scheduler在JobDetail将要执行时候调用
     */
    @Override
    public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
        String name = jobExecutionContext.getJobDetail().getKey().getName();
        log.info("job的名称是：{},Scheduler在JobDetail将要执行时调用该方法",name);
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
        log.info("JobDetail即将执行，但是被Trigger否决");
    }

    @Override
    public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
        log.info("监听完毕：你执行的任务名称：{}",jobExecutionContext.getJobDetail().getKey().getName());
    }
}
